import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";



Vue.use(VueRouter);

import Vuex from "../store/index.js";

console.log(Vuex)

const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    path: "/login",
    name: "login",
    component: () =>
      import("../views/Login.vue"),
  },
  {
    path: "/detail",
    name: "detail",
    component: () =>
      import("../views/detail.vue"),
  },
  {
    path: "/videos",
    name: "videos",
    component: () =>
      import("../views/Videos.vue"),
  },
  {
    path: "/class",
    name: "class",
    component: () =>
      import("../views/Class.vue"),
  },
  {
    path: "/talk",
    name: "talk",
    component: () =>import("../views/Talk.vue"),
    beforeEnter:(to,from,next)=>{
      console.log(to,from)
      let token = Vuex.state.token
      if(token){
        console.log(token,"123123")
        next();
      }else{
        next({name:"login",params:{name:"talk"}});
      }
      
    }

  },
  {
    path: "/my",
    name: "my",
    component: () =>
      import("../views/My.vue"),
      beforeEnter:(to,from,next)=>{
        console.log(to,from)
        let token = Vuex.state.token
        if(token){
          console.log(token)
          next();
        }else{
          next({name:"login",params:{name:"my"}});
        }
        
      }
  }
];


const router = new VueRouter({
  routes,
});

export default router;
